package cn.cutie.clot.gateway;

import cn.cutie.clotrpc.core.api.RegistryCenter;
import cn.cutie.clotrpc.core.registry.clot.ClotRegistryCenter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping;

import java.util.Properties;

import static cn.cutie.clot.gateway.plugin.GatewayPlugin.GATEWAY_PREFIX;

/**
 * @Description:
 * @Author: Cutie
 * @CreateDate: 2024/6/4 17:47
 * @Version: 0.0.1
 */
@Configuration
public class GatewayConfig {
    @Bean
    public RegistryCenter rc(){
        return new ClotRegistryCenter();
    }

    @Bean
    ApplicationRunner runner(@Autowired ApplicationContext context) {
        return args -> {
            SimpleUrlHandlerMapping handlerMapping = context.getBean(SimpleUrlHandlerMapping.class);
            Properties mappings = new Properties();
            mappings.put(GATEWAY_PREFIX + "/**", "gatewayWebHandler");
            handlerMapping.setMappings(mappings);
            handlerMapping.initApplicationContext();
            System.out.println("clot-rpc gateway start");
        };
    }

}
